package tj.eskhata.pos.dao.hibernate;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.asm.Type;

import tj.eskhata.pos.dao.UserDao;
import tj.eskhata.pos.domain.Certificate;
import tj.eskhata.pos.domain.Client;
import tj.eskhata.pos.domain.User;

public class UserDaoImpl extends AbstractHibernateDaoImpl<User>
    implements UserDao {

  public UserDaoImpl() {
    super(User.class);    
  }
  
  public boolean isUserInGroup(User user, String groupCode) {
	  Connection con=getSession().connection();
	  boolean result=false;
	  ResultSet rs;
	  Certificate cert= new Certificate();
	  String s="";
	  
	  try {
		CallableStatement clst= con.prepareCall("{?= call USERS#.ISUSERINGROUP(?,?)}");
		clst.registerOutParameter(1, Type.LONG);
		clst.setLong	(2, user.getId());
		clst.setString	(3, groupCode);
		clst.execute();
		s=clst.getString(1);
		
		if(s.equals("1"))
			result=true;
		else
			result=false;		
        
	  } catch (SQLException e) {
		e.printStackTrace();
	  }
		  
	  return result;
  }
}
